<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
        <link href="./resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
    </h:head>

    <body>
        <ui:composition template="./WEB-INF/templates/template.xhtml">
            <ui:define name="content">

                <!-- Datatable goes here -->

                <h:form id="form">

                    <p:growl id="messages" showDetail="true" life="900"/>
                    <h:panelGroup rendered="#{tUnitsController.items.rowCount > 0}">
                        <h:outputText value="#{tUnitsController.pagination.pageFirstItem + 1}..#{tUnitsController.pagination.pageLastItem + 1}/#{tUnitsController.pagination.itemsCount}"/>&nbsp;
                        <h:commandLink action="#{tUnitsController.previous}" value="#{bundle.Previous} #{tUnitsController.pagination.pageSize}" rendered="#{tUnitsController.pagination.hasPreviousPage}"/>&nbsp;
                        <h:commandLink action="#{tUnitsController.next}" value="#{bundle.Next} #{tUnitsController.pagination.pageSize}" rendered="#{tUnitsController.pagination.hasNextPage}"/>&nbsp;
                        <p:dataTable var="item" value="#{tUnitsController.items}" id="items" editable="true" resizableColumns="true" paginator="false" rows="20" sortMode="multiple">

                            <f:facet name="header">
                                View All Units
                            </f:facet>

                            <p:ajax event="rowEdit" listener="#{tUnitsController.prepareEditt}" update=":form:messages" />
                            <p:ajax event="rowEditCancel" listener="#{tUnitsController.onCancel}" update=":form:messages" />

                            <p:column headerText="Unit ID" sortBy="#{item.id}" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.id}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.id}" />
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Make"  sortBy="#{item.make}" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.make}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.make}" />
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>

                            <p:column headerText="Model" sortBy="#{item.model}" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.model}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.model}"  label="Model"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Year" sortBy="#{item.year}" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.year}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.year}"  label="Year"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Purchase Price" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.origPurchasePrice}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.origPurchasePrice}" label="Purchase Price"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Fuel Type" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.fuelType}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.fuelType}"  label="Fuel Type"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>

                            <p:column headerText="Owner" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.owner}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.owner}"  label="Owner"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Operator" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.operator}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.operator}"  label="Operator"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Out of Stock" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.decommFlag}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.decommFlag}"  label="Remove From Stock"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="PO #" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.poNum}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.poNum}" label="PO #"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Service #"  style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{item.serviceNum}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{item.serviceNum}"  label="Service #"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Edit &amp; Tires" style="width: 6%; font-size: 12px">
                                <p:rowEditor/>
                                <p:commandLink id="viewInv" value="Tires"/>
                            </p:column>
                        </p:dataTable>
                    </h:panelGroup>
                </h:form>

                <!-- End of Datatable -->

            </ui:define>

        </ui:composition>

    </body>
</html>
